{% extends 'blank.html.twig' %}
{% block body %}
    <div>
        <span>加密文字：</span>
        <input id="textinfo" type="text" value="">
        <button class="uploadify-button" onclick="ApiRequest()">后端加密</button>
    </div>
    <span>后端加密后的字符串：</span>
    <div id="showencrypt"></div>
    <div><span>前端解密解密的字符串：</span><button class="uploadify-button" onclick="Decrypt()">js解密</button></div>
    <div id="showdecrypt"></div>
{% endblock %}
{% block footer %}
    <script type="text/javascript" src="/AbsSR/web/static/common/js/aes/aes.js"></script>
    <script type="text/javascript" src="/AbsSR/web/static/huiadmin/lib/jquery/1.9.1/jquery.js"></script>
    <script type="text/javascript" src="/AbsSR/web/static/common/js/aes/aes-json-format.js"></script>
    <script type="text/javascript">

        //js解密函数
        function Decrypt(){
            //获取被加密字符串
            var _strTextInfo = $('#showencrypt').html();
            //获取加密秘钥
            var _strSecrectInfo = 'happykala_red_ls';
            var _strDecryptText = JSON.parse(CryptoJS.AES.decrypt(_strTextInfo, _strSecrectInfo, {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8));
            $('#showdecrypt').html(_strDecryptText);
        }
        //api请求函数传递要加密的字符串到后端，后端加密之后返回
        function ApiRequest(){
            $.ajax({
                type:'POST',
                url:'{{ path('endecrypt_back') }}',
                data:{
                    encryptvalue:$('#textinfo').val()
                },
                success:function(msg){
                    $('#showencrypt').html(msg);
                }
            });
        }
    </script>
{% endblock %}